export default class Food {
    constructor(map){
        this.map = map

        //自己创建一个食物
        this.food = document.createElement('div')
        this.food.className = 'food'
        //插入地图
        this.map.appendChild(this.food)
        //准备两个变量准备坐标
        this.x = 0
        this.y = 0
        this.newFood()
    }
    //准备一个方法 制作随机坐标
    newFood () {
        //1-1 计算横向纵向一共可以放多少个食物
        const xNum = (this.map.clientWidth-20) / 25
        const yNum = (this.map.clientHeight-20) / 25

        // console.log(xNum,yNum);  //横向可以打印32个食物，纵向可以打印24和食物
        //1-2 随机出现0-32   0-24 之间的随机数
        const x = Math.floor(Math.random() * (xNum - 0 ) + 0)
        const y = Math.floor(Math.random() * (yNum - 0 ) + 0)
        // console.log(x,y );
        //1-3 做出坐标位置 x/y*25
        this.x = x*25
        this.y = y*25
        //1-4 赋值
        this.food.style.left = this.x +'px'
        this.food.style.top = this.y +'px'



    }
}